/**
 * 初始化部门详情对话框
 */
var IsRevisitInfoDlg = {
    isRevisitInfoData: {},
    zTreeInstance: null,
    validateFields: {}
};

/**
 * 清除数据
 */
IsRevisitInfoDlg.clearData = function () {
    this.isRevisitInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
IsRevisitInfoDlg.set = function (key, val) {
    this.isRevisitInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
IsRevisitInfoDlg.get = function (key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
IsRevisitInfoDlg.close = function () {
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.close(index);
}


/**
 * 显示部门选择的树
 *
 * @returns
 */
IsRevisitInfoDlg.showIsRevisitSelectTree = function () {
    var pName = $("#pName");
    var pNameOffset = $("#pName").offset();
    $("#parentIsRevisitMenu").css({
        left: pNameOffset.left + "px",
        top: pNameOffset.top + pName.outerHeight() + "px"
    }).slideDown("fast");

    $("body").bind("mousedown", onBodyDown);
}

/**
 * 隐藏部门选择的树
 */
IsRevisitInfoDlg.hideIsRevisitSelectTree = function () {
    $("#parentIsRevisitMenu").fadeOut("fast");
    $("body").unbind("mousedown", onBodyDown);// mousedown当鼠标按下就可以触发，不用弹起
}

/**
 * 收集数据
 */
IsRevisitInfoDlg.collectData = function () {
    this.set('id').set('status').set('follower').set('statuss').set('reservationsId').set('revisitContent').set('isReturnVisit').set('reservations').set('remarksOfReturnVisit').set('causeOfNoReturnVisit').set('appointmentTime');
}

/**
 * 验证数据是否为空
 */
IsRevisitInfoDlg.validate = function () {
    $('#isRevisitInfoForm').data("bootstrapValidator").resetForm();
    $('#isRevisitInfoForm').bootstrapValidator('validate');
    return $("#isRevisitInfoForm").data('bootstrapValidator').isValid();
}

function onBodyDown(event) {
    if (!(event.target.id == "menuBtn" || event.target.id == "parentIsRevisitMenu" || $(
            event.target).parents("#parentIsRevisitMenu").length > 0)) {
        IsRevisitInfoDlg.hideIsRevisitSelectTree();
    }
}

/**
 * 提交添加补单预约客户
 */
IsRevisitInfoDlg.addIsRevisit = function () {
    var appointmentTime = $('#appointmentTime')[0];
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    if (document.getElementById("noRevisit").checked == true) {
        if (document.getElementById("causeOfNoReturnVisit").value == null || document.getElementById("causeOfNoReturnVisit").value == "") {
            alert("请输入不回访原因");
            return;
        }
    }
    if (document.getElementById("revisit").checked == true) {
        if (document.getElementById("reservations").value == null || document.getElementById("reservations").value == "") {
            alert("请输入预约回访人");
            return;
        }
    }
    if (document.getElementById("revisit").checked == true) {
        if (document.getElementById("appointmentTime").value == null || document.getElementById("appointmentTime").value == "") {
            alert("请输入预约回访时间");
            return;
        }
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/customer/add_isRevisit", function (data) {
        Feng.success("操作成功!");
        window.parent.Consultant.table.refresh();
        IsRevisitInfoDlg.close();
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.isRevisitInfoData);
    ajax.start();
}

/**
 * 提交添加补单预约客户
 */
IsRevisitInfoDlg.addIsRevisits = function () {
    var appointmentTime = $('#appointmentTime')[0];
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    if (document.getElementById("noRevisit").checked == true) {
        if (document.getElementById("causeOfNoReturnVisit").value == null || document.getElementById("causeOfNoReturnVisit").value == "") {
            alert("请输入不回访原因");
            return;
        }
    }
    if (document.getElementById("revisit").checked == true) {
        if (document.getElementById("reservations").value == null || document.getElementById("reservations").value == "") {
            alert("请输入预约回访人");
            return;
        }
    }
    if (document.getElementById("revisit").checked == true) {
        if (document.getElementById("appointmentTime").value == null || document.getElementById("appointmentTime").value == "") {
            alert("请输入预约回访时间");
            return;
        }
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/customer/add_isRevisit", function (data) {
        Feng.success("操作成功!");
        window.parent.Customer.table.refresh();
        IsRevisitInfoDlg.close();
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.isRevisitInfoData);
    ajax.start();
}

/**
 * 提交添加补单预约客户
 */
IsRevisitInfoDlg.addIsRevisitsd = function () {
    this.clearData();
    this.collectData();
    if (document.getElementById("appointmentTime").value == null || document.getElementById("appointmentTime").value == "") {
        var selectStr = $("#statuss").val();
        if(selectStr !='过期'){
            alert("请输入预约回访时间");
            return;
        }
    }
    if (document.getElementById("revisitContent").value == null || document.getElementById("revisitContent").value == "") {
        alert("请输入回访记录");
        return;
    }
    if (document.getElementById("follower").value == null || document.getElementById("follower").value == "") {
        alert("请输入跟进人");
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/reservations/add_isRevisit", function (data) {
        Feng.success("操作成功!");
        window.parent.ReservationsRecordTable.table.refresh();
        IsRevisitInfoDlg.close();
        // $('#cancel', parent.document).click();
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.isRevisitInfoData);
    ajax.start();
}

/**
 * 提交添加补单预约客户
 */
IsRevisitInfoDlg.addIsRevisitsdds = function () {
    this.clearData();
    this.collectData();
    if (document.getElementById("appointmentTime").value == null || document.getElementById("appointmentTime").value == "") {
        var selectStr = $("#statuss").val();
        if(selectStr !='过期'){
            alert("请输入预约回访时间");
            return;
        }
    }
    if (document.getElementById("revisitContent").value == null || document.getElementById("revisitContent").value == "") {
        alert("请输入回访记录");
        return;
    }
    if (document.getElementById("follower").value == null || document.getElementById("follower").value == "") {
        alert("请输入跟进人");
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/reservations/add_isRevisit", function (data) {
        Feng.success("操作成功!");
        window.parent.ReservationsRecordTable.table.refresh();
        IsRevisitInfoDlg.close();
        // $('#cancel', parent.document).click();
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.isRevisitInfoData);
    ajax.start();
}


/**
 * 提交添加补单预约客户
 */
IsRevisitInfoDlg.addIsRevisitsdr = function () {
    this.clearData();
    this.collectData();
    if (document.getElementById("appointmentTime").value == null || document.getElementById("appointmentTime").value == "") {
        var selectStr = $("#statuss").val();
        if(selectStr !='过期'){
            alert("请输入预约回访时间");
            return;
        }
    }
    if (document.getElementById("revisitContent").value == null || document.getElementById("revisitContent").value == "") {
        alert("请输入回访记录");
        return;
    }
    if (document.getElementById("follower").value == null || document.getElementById("follower").value == "") {
        alert("请输入跟进人");
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/reservations/add_isRevisit", function (data) {
        Feng.success("操作成功!");
        window.parent.RevisitRecord.table.refresh();
        IsRevisitInfoDlg.close();
        // $('#cancel', parent.document).click();
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.isRevisitInfoData);
    ajax.start();
}

/**
 * 提交添加补单预约客户
 */
IsRevisitInfoDlg.addIsRevisitsddsr = function () {
    this.clearData();
    this.collectData();
    if (document.getElementById("appointmentTime").value == null || document.getElementById("appointmentTime").value == "") {
        var selectStr = $("#statuss").val();
        if(selectStr !='过期'){
            alert("请输入预约回访时间");
            return;
        }
    }
    if (document.getElementById("revisitContent").value == null || document.getElementById("revisitContent").value == "") {
        alert("请输入回访记录");
        return;
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/reservations/add_isRevisit", function (data) {
        Feng.success("操作成功!");
        window.parent.RevisitRecord.table.refresh();
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        parent.layer.close(index);
        // $('#cancel', parent.document).click();
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.isRevisitInfoData);
    ajax.start();
}

IsRevisitInfoDlg.addIsRevisitsds = function () {
    var appointmentTime = $('#appointmentTime')[0];
    this.clearData();
    this.collectData();
    if (!this.validate()) {
        return;
    }
    if (document.getElementById("noRevisit").checked == true) {
        if (document.getElementById("causeOfNoReturnVisit").value == null || document.getElementById("causeOfNoReturnVisit").value == "") {
            alert("请输入不回访原因");
            return;
        }
    }
    if (document.getElementById("revisit").checked == true) {
        if (document.getElementById("reservations").value == null || document.getElementById("reservations").value == "") {
            alert("请输入预约回访人");
            return;
        }
    }
    if (document.getElementById("revisit").checked == true) {
        if (document.getElementById("appointmentTime").value == null || document.getElementById("appointmentTime").value == "") {
            alert("请输入预约回访时间");
            return;
        }
    }
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/doctorLooked/add_isRevisitd", function (data) {
        Feng.success("操作成功!");
        window.parent.DoctorLooked.table.refresh();
        IsRevisitInfoDlg.close();
    }, function (data) {
        Feng.error("操作失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.isRevisitInfoData);
    ajax.start();
}

$(function () {
    Feng.initValidator("isRevisitInfoForm", IsRevisitInfoDlg.validateFields);
    var radios = document.getElementsByName('radio');
    for (var i = 0; i < radios.length; i++) {
        radios[i].indexs = i + 1;
        radios[i].onchange = function () {
            document.getElementById('url1').value = '';
            if (this.checked) {
                document.getElementById("url2").style.display = "none";
                document.getElementById("url1").style.display = "none";
                document.getElementById("causeOfNoReturnVisit").value = "";
                document.getElementById("remarksOfReturnVisit").value = "";
                document.getElementById("appointmentTime").value = "";
                document.getElementById('url1').selectedIndex = "";
                document.getElementById('url2').value = '';
                document.getElementById("url" + this.indexs).style.display = "block";
            }
        }
    }

});